﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAPL.Language.Ast.Utils;

namespace YAPL.Language.Ast {
	public class WhileExpression : Expression {
		private readonly Expression _condition;
		private readonly CodeBlockExpression _body;
		public WhileExpression(ExpressionType nodeType, Type type, Expression condition, CodeBlockExpression body) : base(nodeType, type) {
			_condition = condition;
			_body = body;
		}

		public WhileExpression(ExpressionType nodeType, Type type, bool canRead, bool canWrite, Expression condition, CodeBlockExpression body) : base(nodeType, type, canRead, canWrite) {
			_condition = condition;
			_body = body;
		}

		[Descendant(AstVisit.AfterCurrent, Priority = 0)]
		public Expression Condition {
			get { return _condition; }
		}

		[Descendant(AstVisit.AfterCurrent, Priority = 1)]
		public CodeBlockExpression Body {
			get { return _body; }
		}

		public override bool NodeEquals(Expression other) {
			return (other is WhileExpression);
		}

		public override bool RewriteChild(Expression child, Expression newExpression) {
			throw new System.NotImplementedException();
		}
	}
}
